import hRequest from "@service/index";
import type { Tpage_post } from "@/models/page_post";
import type { Tpost } from "@/models/post";
import type { Trestem } from "@/models/restem";
import { Tcomment } from "@/models/comment";

export async function post_get(params) {
    const res = await hRequest.get<Tpage_post>({ url: "/post/page", params });
    return res;
}

export async function post_like(data) {
    const res = await hRequest.post<Trestem & { data: Tpost }>({ url: `/post/likes/${data.id}`, params: { userId: data.userId } });
    return res;
}

export async function post_getone(data) {
    const res = await hRequest.get<Trestem & { data: Tpost }>({ url: `/post/getOne/${data}` });
    return res;
}

export async function post_add(data) {
    const res = await hRequest.post<Trestem & { data: Tpost }>({ url: "/post/add", data }, "application/json");
    return res;
}

export async function get_MyPost(params) {
    const res = await hRequest.get<Tpage_post>({ url: "/user/getMyPost", params });
    return res;
}

export async function del_post(data) {
    const res = await hRequest.delete<Tpage_post>({ url: "/multipart/delete", data });
    return res;
}

export async function del_postlist(data) {
    const res = await hRequest.delete<Trestem>({ url: `/post/delete/${data.id}`, data });
    return res;
}

export async function post_cancel(data) {
    const res = await hRequest.delete<Trestem>({ url: `/post/likes/${data.id}`, data });
    return res;
}

export async function get_comment(data) {
    const res = await hRequest.get<Trestem & { data: Tcomment[] }>({ url: `/comment/getComment/${data.postId}` });
    return res;
}

export async function add_comment(data, params?: any) {
    const res = await hRequest.post<Trestem & { data: Tcomment }>({ url: "/comment/add", data, params }, "application/json");
    return res;
}

export async function update_post(data) {
    const res = await hRequest.put<Trestem & { data: any }>({ url: `/post/update/${data.id}`, params: { id: data.id }, data }, "application/json");
    return res;
}